package com.lmpop.trade.backupDB;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.OutputStreamWriter;
import java.util.Hashtable;

public class properties
{
  public void WriteToFile(Hashtable map)
  {
    String basepath = Thread.currentThread().getContextClassLoader().getResource("").toString();
    String fieldspath = basepath.substring(5, basepath.length()) + "sysconfig.properties";
    try
    {
      StringBuffer inStr = new StringBuffer();
      FileReader ffield = new FileReader(fieldspath);
      BufferedReader fieldbuff = new BufferedReader(ffield);
      String fieldline = fieldbuff.readLine();
      BufferedWriter bwrite = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fieldspath)));
      while (fieldline != null)
      {
        if (!fieldline.trim().equalsIgnoreCase(""))
        {
          if (!fieldline.substring(0, 1).equalsIgnoreCase("#"))
          {
            String[] fieldlinestr = fieldline.split("=");
            if (map.get(fieldlinestr[0]) != null)
              fieldlinestr[1] = map.get(fieldlinestr[0]).toString();
            fieldline = fieldlinestr[0] + "=" + fieldlinestr[1];
          }
        }
        inStr.append(fieldline);
        inStr.append("\n");

        fieldline = fieldbuff.readLine();
      }
      bwrite.write(inStr.toString());

      fieldbuff.close();
      fieldbuff = null;
      ffield.close();
      ffield = null;

      bwrite.flush();
      bwrite.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

}